/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.plan.dto;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.javaeye.common.dto.DTO;

public class MaterialRequisiteForm implements DTO {
	
	public static final int MATERIAL_REQUISITE_FORM_STATUS_CREATE = 1;
	public static final int MATERIAL_REQUISITE_FORM_STATUS_CHECKED = 2;
	public static final int MATERIAL_REQUISITE_FORM_WAIT_IN_STORE = 3;
	public static final int MATERIAL_REQUISITE_FORM_STATUS_FINISH = 10;
	
	public static final int FORM_TYPE_REQUISITE = 0;
	public static final int FORM_TYPE_QUALIFIED_BACK = 1;
	public static final int FORM_TYPE_UNQUALIFIED_BACK = 2;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6894920169941893269L;

	private String id;
	
	private Date createDate;
	
	private String deptName;
	
	private int deptId;
	
	private String person;
	
	private Integer status;
	
	private String removeDetailIds;
	
	private String planNo;
	
	private int type;
	
	private String sourceFormId;

	private Set<MaterialRequisiteFormDetail> formDetails = new HashSet<MaterialRequisiteFormDetail>();

	public void addDetail(MaterialRequisiteFormDetail detail) {
		detail.setForm(this);
		formDetails.add(detail);
	}
	
	public List<Integer> getRemoveDetailIdList() {
		List<Integer> ret = new ArrayList<Integer>();
		if (removeDetailIds != null && !"".equals(removeDetailIds.trim()) ) {
			String[] deleteIds = removeDetailIds.split(",");
			for (String deleteId : deleteIds) {
				if (!"".equals(deleteId)) {
					ret.add(new Integer(deleteId));
				}
			}
		}
		return ret;
	}
	
	public MaterialRequisiteForm copy() {
		MaterialRequisiteForm form = new MaterialRequisiteForm();
		form.createDate = createDate;
		form.deptName = deptName;
		form.deptId = deptId;
		form.person = person;
		form.status = status;
		form.planNo = planNo;
		form.type = type;
		for (MaterialRequisiteFormDetail detail : formDetails) {
			form.addDetail(detail.copy());
		}
		return form;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getDeptName() {
		return deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	public int getDeptId() {
		return deptId;
	}

	public void setDeptId(int deptId) {
		this.deptId = deptId;
	}

	public String getPerson() {
		return person;
	}

	public void setPerson(String person) {
		this.person = person;
	}
	
	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getStatus() {
		return status;
	}
	
	public String getStatusName() {
		switch (status) {
		case MATERIAL_REQUISITE_FORM_STATUS_CREATE :
			return "新建";
		case MATERIAL_REQUISITE_FORM_STATUS_CHECKED :
			return "检验完成";
		case MATERIAL_REQUISITE_FORM_WAIT_IN_STORE :
			return "等待入库";
		case MATERIAL_REQUISITE_FORM_STATUS_FINISH :	
			return "结束";
		default :
			return "";
		}
	}
	
	public String getTypeName() {
		switch (type) {
		case FORM_TYPE_REQUISITE :
			return "领料单";
		case FORM_TYPE_QUALIFIED_BACK :
			return "合格品退料单";
		case FORM_TYPE_UNQUALIFIED_BACK :
			return "不合格品退料单";
		default :
			return "";
		}
	}

	public Set<MaterialRequisiteFormDetail> getFormDetails() {
		return formDetails;
	}

	public void setFormDetails(Set<MaterialRequisiteFormDetail> formDetails) {
		this.formDetails = formDetails;
	}

	public void setRemoveDetailIds(String removeDetailIds) {
		this.removeDetailIds = removeDetailIds;
	}

	public String getRemoveDetailIds() {
		return removeDetailIds;
	}

	public String getPlanNo() {
		return planNo;
	}

	public void setPlanNo(String planNo) {
		this.planNo = planNo;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public void setSourceFormId(String sourceFormId) {
		this.sourceFormId = sourceFormId;
	}

	public String getSourceFormId() {
		return sourceFormId;
	}
	
}
